<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 配送时间维护表
 * @package  module/base/bill
 * create by allen.qiang
 * @version 1.0
 */

class goodsDeliver {

    /**
     * 查询商品配送时间
     * @param array $arg_array
     * @return null|array
     */
    public function searchGoodsDeliverRelation( &$arg_array ) {

        global $G_SHOP;

        //sql字符串
        $sql = '';

        //参数类型字符串
        $params_type = '';

        //参数值数组
        $params_array = array();

        //商品网购号
        if (isset($arg_array['postID']) && is_numeric($arg_array['postID'])) {
            $sql .= ' AND postID = ?';
            $params_type .= 'i';
            $params_array[] = $arg_array['postID'];
        }

        //下单开始时间
        if (isset($arg_array['nowTime']) && !empty($arg_array['nowTime'])) {
            $sql .= ' AND startOrderTime < ?';
            $params_type .= 's';
            $params_array[] = $arg_array['nowTime'];
        }

        //下单结束时间
        if (isset($arg_array['nowTime']) && !empty($arg_array['nowTime'])) {
            $sql .= ' AND endOrderTime > ?';
            $params_type .= 's';
            $params_array[] = $arg_array['nowTime'];
        }

        if ($sql) {
            $sql = ' WHERE ' . substr($sql, 4);
        }


        //排序
        if (isset($arg_array['sortname']) && !empty($arg_array['sortname']))
            $sql .= sprintf(' ORDER BY %s %s', $arg_array['sortname'], $arg_array['sortorder']);


        //查询信息
        $search_sql = 'SELECT * FROM goods_deliver_relation ' . $sql;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query($search_sql, $params_type, $params_array);
        if (!$temp_item_array) {
            return null;
        }

        $item_array = array();

        foreach ($temp_item_array as $deliver) {

            $item_array[] = array(
                'postID' => $deliver->postID,
                'startOrderTime' => $deliver->startOrderTime,
                'endOrderTime' => $deliver->endOrderTime,
                'startDeliverTime' => $deliver->startDeliverTime,
                'endDeliverTime' => $deliver->endDeliverTime
            );
        }

        return $item_array;

    }


}